﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BySoft.Server.Business;
using BySoft.Server.Common.Schema;
using BySoft.Web.Utility;
using BySoft.Server.Common;
using BySoft.Web.Controls;

namespace BySoft.Web.Site.SysManage
{
    public partial class ExceptionLogList :  AuthBasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitControl();
                BindData(0);

            }
        }

        private void InitControl()
        {
            DataTable dt = SysExceptonlog.GetExceptionTypeList();
            ddlExceptionType.DataValueField = SysExceptonlogTable.C_EXCEPTIONTYPE;
            ddlExceptionType.DataTextField = SysExceptonlogTable.C_EXCEPTIONTYPE;
            ddlExceptionType.DataSource = dt;
            ddlExceptionType.DataBind();

            dt = SysModule.GetLeftModuleList();
            ddlModule.DataTextField = SysModuleTable.C_MODULENAME;
            ddlModule.DataValueField = SysModuleTable.C_MODULEID;
            ddlModule.DataSource = dt;
            ddlModule.DataBind();

            UIHelper.InsertFirstItem(ddlModule);
            UIHelper.InsertFirstItem(ddlExceptionType);
        }

        private int m_count = 0;

        private void BindData(int pageIndex)
        {
            DataTable dtData = SysExceptonlog.GetExceptionLogList(ddlModule.SelectedValue, clpStartDate.Value,
                clpEndDate.Value, ddlExceptionType.SelectedValue, pageIndex, pcData.PageSize, out m_count);

            pcData.RecordCount = m_count;
            if (dtData.Rows.Count > 0)
            {
                grdResult.DataSource = dtData;
                grdResult.DataBind();
                pcData.CurrentIndex = pageIndex;
            }
            else
            {
                UIHelper.BindEmptyGridView(grdResult, dtData);
            }
        }

        protected void btnExport_Click(object sender, ImageClickEventArgs e)
        {
            DataTable dtData = SysExceptonlog.GetExceptionLogList(ddlModule.SelectedValue, clpStartDate.Value,
                clpEndDate.Value, ddlExceptionType.SelectedValue, 0, 0, out m_count);
            CommonMethod.ExportExcel(dtData, grdResult, null);
        }


        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindData(0);
        }


        protected void pcData_PageIndexClick(object sender, PageIndexClickEventArgs e)
        {
            BindData(e.PageIndex);
        }
    }
}
